package com.yyj.jan.user.controller;

import com.yyj.jan.redis.IRedisService;
import com.yyj.jan.redis.RedisDao;
import com.yyj.jan.user.entity.User;
import com.yyj.jan.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/user")
@EnableAsync
public class UserController {

    @Autowired
    private UserService userService;

    @Autowired
    private IRedisService redisService;
    @Resource
    private RedisDao redisDao;

    private List<User> userList;

    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public List<User> list(){
        return userService.findAll();
    }

    @RequestMapping(value="/setredis",method = RequestMethod.GET)
    public String setRedis(){

        List<User> list = userService.findAll();
        redisService.set("redis","redis的value");
        redisDao.setKey("wocao","nimabi");
        redisService.setList("userList",list);
        redisService.expire("userList",10);
        return "set redis is ok ";
    }

    @RequestMapping(value="/getredis",method = RequestMethod.GET)
    public  List<User> getRedis(){
        String v = redisService.get("redis");
        return redisService.getList("userList",User.class);
    }




}
